using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Diagnostics.Contracts;
using Konst3d.Efficiency.Suite;

namespace PEM
{
    /// <summary>
    /// Interaction logic for CreateEditBuyDialog.xaml
    /// </summary>
    public partial class CreateEditBuyDialog : PersistentModalDialog
    {
        public string BuyTitle
        {
            get
            {
                return uiBuyTitleTextBox.Text;
            }
        }

        public string BuyDescription
        {
            get
            {
                return uiBuyDescrTextBox.Text;
            }
        }

        public int BuySeverity
        {
            get
            {
                return Int32.Parse(uiBuySeverity.Text);
            }
        }

        public double BuyPrice
        {
            get
            {
                return Double.Parse(uiBuyPrice.Text);
            }
        }

        public DateTime BuyDeadLine
        {
            get
            {
                return uiBuyDeadLineCalendar.SelectedDate ?? DateTime.Now;
            }
        }

        public CreateEditBuyDialog()
        {
            InitializeComponent();
        }

        public bool ShowDialog(Window owner, IBuy buy)
        {
            Contract.Requires(buy != null);

            uiBuyTitleTextBox.Text = buy.Title;
            uiBuyDescrTextBox.Text = buy.Description;
            uiBuySeverity.Text = buy.Severity.ToString();
            uiBuyPrice.Text = buy.Price.ToString();
            uiBuyDeadLineCalendar.SelectedDate = buy.DeadLine;

            return ShowDialog(owner);
        }

        private void OnCreateButtonClick(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
        }

        private void OnCancelButtonClick(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }
    }
}
